package cn.initcap.concurrency.classloader;

/**
 * 方法动态分派演示
 *
 * @author initcap
 * @date Created in 2018/7/26 AM9:24.
 */
public class DynamicDispatch {

    public static void main(String[] args) {
        BaseHuman man = new Man();
        BaseHuman woman = new Woman();
        man.sayHello();
        woman.sayHello();
        man = new Woman();
        man.sayHello();
    }

    static abstract class BaseHuman {
        protected abstract void sayHello();
    }

    static class Man extends BaseHuman {

        @Override
        protected void sayHello() {
            System.out.println("man say hello");
        }
    }

    static class Woman extends BaseHuman {

        @Override
        protected void sayHello() {
            System.out.println("woman say hello");
        }
    }

}
